#ifndef ALGORITHM_H
#define ALGORITHM_H

#include <cstring>
#include <fstream>
using std::ifstream;



#include "set.h"

void swap( int* a, int* b ){
	int temp = *a;
	*a = *b;
	*b = temp;
}

void print(int* s, int k){
	for(int i = 0; i < k; ++i)
		cout << s[i] << " ";
	cout << endl;
}

bool isValid(int* s, int k){
	for( int i = 0; i < k; ++i ){
		for( int j = i+1; j < k; ++j ){
			if( s[i] == s[j] ){
				print(s,k);
				return false;
			}
		}
	}
	return true;
}

struct intersection_info{
	int id_set;
	int cardinality_after_intersection;
	int cardinality;
	int is_in_solution;
};

int compareIntersectionInfo(const void* a, const void* b){
	if( ((struct intersection_info*)a)->is_in_solution != ((struct intersection_info*)b)->is_in_solution )
		return ((struct intersection_info*)a)->is_in_solution == 1;
		
	if( ((struct intersection_info*)a)->cardinality_after_intersection == ((struct intersection_info*)b)->cardinality_after_intersection )
		return ((struct intersection_info*)a)->cardinality < ((struct intersection_info*)b)->cardinality;
	return ((struct intersection_info*)a)->cardinality_after_intersection < ((struct intersection_info*)b)->cardinality_after_intersection;
}

class Algorithm{
	public:
		Algorithm( const char* );
		~Algorithm();
		
		virtual void solve() = 0;
		virtual int getQualityOfBest() = 0;
		bool isValidSolution(int*);
		
	protected:
		int L;
		int k;
		Set *sets;
		const char* input_file;
		time_t start_time;
};

#include "algorithm.cpp"

#endif